#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 4e4 + 5;
const int K = 2e4 + 5;

int n, k;
int head[N];
int ver[N << 1], W[N << 1], Next[N << 1], tot;
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
ll ans;
int del[N], sz[N], mx[N], rt;
void get_rt(int u, int fu, int cnt) {
  sz[u] = 1, mx[u] = 0;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (del[v] || v == fu) continue;
    get_rt(v, u, cnt);
    sz[u] += sz[v];
    mx[u] = max(mx[u], sz[v]);
  }
  mx[u] = max(mx[u], cnt - sz[u]);
  if (!rt || mx[rt] > mx[u]) rt = u;
}
int bit[K];  // store count of dis + 1
int lowbit(int x) { return x & -x; }
void update(int x, int d) {
  for (int i = x; i <= k + 1; i += lowbit(i)) bit[i] += d;
}
int query(int x) {
  int res = 0;
  for (int i = x; i > 0; i -= lowbit(i)) res += bit[i];
  return res;
}
void get_dis(int u, int fu, int d, vector<int>& res) {
  res.push_back(d);
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (del[v] || v == fu) continue;
    get_dis(v, u, d + W[i], res);
  }
}
void calc(int u) {
  vector<int> dis;
  dis.push_back(0), update(1, 1);
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (del[v]) continue;
    vector<int> now;
    get_dis(v, u, W[i], now);
    for (int x : now) {
      if (x <= k) ans += query(k - x + 1);
    }
    for (int x : now)
      if (x <= k) dis.push_back(x), update(x + 1, 1);
  }
  for (int x : dis) update(x + 1, -1);
}
void divide(int u, int cnt) {
  rt = 0;
  get_rt(u, 0, cnt);
  u = rt;
  calc(rt);
  del[rt] = 1;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (del[v]) continue;
    divide(v, sz[v] > sz[u] ? sz[v] - sz[u] : sz[v]);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 2, n) {
    int u, v, w;
    cin >> u >> v >> w;
    add(u, v, w), add(v, u, w);
  }
  cin >> k;
  divide(1, n);
  cout << ans;
  return 0;
}